/*package queueddas;

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class Main extends JPanel{
    private JButton bringServe;
    private JComboBox costLineNum;
    private JComboBox costToTableNum;
    private JComboBox costToSeat;
    private JButton moreCost;
    private JButton sitCost;
    private JLabel costumerQueue;
    private JComboBox getOrderTableNum;
    private JButton getGet;
    private JLabel getOrderLabel;
    private JButton getOrderEnlist;
    private JLabel serveOrderLabel;
    private JButton getFood;
    private JLabel bringFoodLabel;
    private JComboBox bringHandSelect;
    private JComboBox bringToTable;
    private JComboBox bringAorB;
    private JLabel collectPayment;
    private JComboBox collectTable;
    private JButton collectGo;
    private JLabel cleanTable;
    private JButton cleanGo;
    private JComboBox cleanTableNum;
    private JButton cleanToWash;
    private JLabel cleanBringTo;
    private JButton cleanPlatesGoGet;
    private JButton cleanPlatesToCounter;
    private JLabel errorText;
    private JLabel errorNoti;
    public JLabel queueStatus;
    public JLabel handContains;
    public int CostumersCreated = 0;
    public Object costumerOrdersAtHand[];
    public int foodRightHand;
    public int foodLeftHand;
    private ImageStore background;
    private Server server;
    private Timer timer;
    private Costumer[] costumers;
    private Table[] tables;
    private LinkedList counterOrderQueue;


    public Main() {//all statements in this constructor are for initialization purposes
       
        //construct preComponents
        String[] costLineNumItems = {"-", "1", "2", "3", "4"};
        String[] costToTableNumItems = {"-", "1", "2", "3", "4", "5"};
        String[] costToSeatItems = {"-", "A", "B"};
        String[] bringHandSelectItems = {"-", "Left Hand", "Right Hand"};
        String[] bringToTableItems = {"-", "1", "2", "3", "4", "5"};
        String[] bringAorBItems = {"-", "A", "B"};
        String[] getOrderAorBItems = {"-", "A", "B"};
        String[] getOrderTableNumItems = {"-", "1", "2", "3", "4", "5"};
        String[] collectTableItems = {"-", "1", "2", "3", "4", "5"};
        String[] cleanTableNumItems = {"-", "1", "2", "3", "4", "5"};

        //construct components
        getOrderTableNum = new JComboBox (getOrderTableNumItems);
        getOrderLabel = new JLabel ("Get Order");
        getOrderEnlist = new JButton ("Enlist Order");
        getGet = new JButton("Get!");
        serveOrderLabel = new JLabel ("Serve Order");
        bringFoodLabel = new JLabel ("Bring Food to:");
        bringHandSelect = new JComboBox (bringHandSelectItems);
        bringToTable = new JComboBox (bringToTableItems);
        bringAorB = new JComboBox (bringAorBItems);
        bringServe = new JButton ("Serve Food");
        costumerQueue = new JLabel ("Costumer:");
        getFood = new JButton ("Get Food");
        collectPayment = new JLabel ("Collect Payment");
        collectTable = new JComboBox (collectTableItems);
        collectGo = new JButton ("Go!");
        cleanTable = new JLabel ("Clean Table");
        cleanGo = new JButton ("Go!");
        cleanTableNum = new JComboBox (cleanTableNumItems);
        cleanToWash = new JButton ("ToDishwash");
        cleanBringTo = new JLabel ("Get Clean Plates");
        cleanPlatesGoGet = new JButton ("Go!");
        cleanPlatesToCounter = new JButton("To Counter");
        errorText = new JLabel ("Errors Here");
        errorNoti = new JLabel ("Error Notifications");
        costLineNum = new JComboBox (costLineNumItems);
        costToTableNum = new JComboBox (costToTableNumItems);
        costToSeat = new JComboBox (costToSeatItems);
        sitCost = new JButton ("Sit");
        moreCost = new JButton("More Costumers!");
        queueStatus = new JLabel("empty queue");
        handContains = new JLabel("LH: RH:");

        //adjust size and set layout
        setPreferredSize (new Dimension (1020, 670));
        setLayout (null);

        //add components
        add (bringServe);
        add (costLineNum);
        add (costToTableNum);
        add (costToSeat);
        add (sitCost);
        add (moreCost);
        add (costumerQueue);
        add (getOrderTableNum);
        add (getOrderLabel);
        add (getOrderEnlist);
        add (serveOrderLabel);
        add (getFood);
        add (bringFoodLabel);
        add (bringHandSelect);
        add (bringToTable);
        add (bringAorB);
        add (collectPayment);
        add (collectTable);
        add (collectGo);
        add (cleanTable);
        add (cleanGo);
        add (cleanTableNum);
        add (cleanToWash);
        add (cleanBringTo);
        add (cleanPlatesGoGet);
        add (cleanPlatesToCounter);
        add (errorText);
        add (errorNoti);
        add (getGet);
        add (queueStatus);
        add (handContains);

        //set component bounds (only needed by Absolute Positioning)
        bringServe.setBounds (25, 230, 110, 25);
        costLineNum.setBounds (785, 625, 40, 20);
        costToTableNum.setBounds (840, 625, 35, 20);
        costToSeat.setBounds (880, 625, 35, 20);
        moreCost.setBounds (550, 625, 140, 20);
        sitCost.setBounds (920, 625, 60, 20);
        costumerQueue.setBounds (715, 625, 65, 20);
        getOrderTableNum.setBounds (25, 40, 35, 25);
        getGet.setBounds(70, 40, 65, 25);
        getOrderLabel.setBounds (15, 20, 60, 25);
        getOrderEnlist.setBounds (25, 70, 110, 25);
        serveOrderLabel.setBounds (15, 100, 75, 25);
        getFood.setBounds (25, 120, 110, 25);
        bringFoodLabel.setBounds (15, 150, 100, 25);
        bringHandSelect.setBounds (25, 200, 80, 25);
        bringToTable.setBounds (25, 170, 35, 25);
        bringAorB.setBounds (65, 170, 35, 25);
        collectPayment.setBounds (20, 260, 100, 25);
        collectTable.setBounds (30, 280, 35, 25);
        collectGo.setBounds (70, 280, 65, 25);
        cleanTable.setBounds (20, 310, 100, 25);
        cleanGo.setBounds (70, 330, 65, 25);
        cleanTableNum.setBounds (30, 330, 35, 25);
        cleanToWash.setBounds (30, 360, 105, 25);
        cleanBringTo.setBounds (20, 390, 115, 25);
        cleanPlatesGoGet.setBounds (30, 410, 105, 25);
        cleanPlatesToCounter.setBounds(30, 440, 105, 25);
        errorText.setBounds (30, 470, 105, 70);
        errorNoti.setBounds (20, 470, 110, 25);
        queueStatus.setBounds(30, 500, 110, 50);
        handContains.setBounds(30, 550, 110, 50);

        //errorText.setForeground(WHITE);

        //images
        background = new ImageStore("bg.jpg");
        server = new Server();
        counterOrderQueue = new LinkedList();
        costumers = new Costumer[12];
        tables = new Table[5];

        tables[0] = new Table();
        tables[1] = new Table();
        tables[2] = new Table();
        tables[3] = new Table();
        tables[4] = new Table();
        
        costumers[0] = new Costumer();

        foodLeftHand = -1;
        foodRightHand = -1;
       
        //handlers
        ButtonHandler buttHandler = new ButtonHandler();
                
        //listners
        getOrderEnlist.addActionListener(buttHandler);
        getGet.addActionListener(buttHandler);
        getFood.addActionListener(buttHandler);
        bringServe.addActionListener(buttHandler);
        collectGo.addActionListener(buttHandler);
        cleanGo.addActionListener(buttHandler);
        cleanToWash.addActionListener(buttHandler);
        sitCost.addActionListener(buttHandler);
        cleanPlatesGoGet.addActionListener(buttHandler);
        cleanPlatesToCounter.addActionListener(buttHandler);
        moreCost.addActionListener(buttHandler);
        
        setDoubleBuffered(true);
        //while(true)
            repaint();
    }

     public void paint(Graphics g){
       super.paint(g);
       Graphics2D backg = (Graphics2D)g;
       Graphics2D server = (Graphics2D)g;
       Graphics2D costumer1 = (Graphics2D)g;
       
       backg.drawImage(background.getImage(), 200, 20, this);
       server.drawImage(this.server.getImage(), this.server.getX(), this.server.getY(), this);
       costumer1.drawImage(costumers[0].getImage(), costumers[0].getX(), costumers[0].getY(), this);
       Toolkit.getDefaultToolkit().sync();
       g.dispose();

   }

    public Object[] getOrderFromCostumers(Object tableNumb){
        int tableNum = 0;
        int ind = -1;
        Object orders[];
        int costNum = 1;
        int ctr, ctr2;
        int costInd, costInd2;
        orders = new Object[2];

        if(tableNumb == "1")
               tableNum = 0;
               else if(tableNumb == "2")
               tableNum = 1;
               else if(tableNumb == "3")
               tableNum = 2;
               else if(tableNumb == "4")
               tableNum = 3;
               else if(tableNumb == "5")
               tableNum = 4;

        if((ind = tables[tableNum].isTableFull()) == -1){
            errorText.setText("No Costumers Yet!"); //print error message: no costumers on table
            orders[0] = "-1";
            orders[1] = "-1";
        }

        else{   if(ind == 0){ //if there is only one costumer at the table
                    for(ctr = 0; ctr < costNum - 1; ctr++)                 //check which costumer is seated at given table
                        if(costumers[ctr].imAtThisTable() == tableNum)
                        costInd = ctr;
                        orders[0] = costumers[ctr].createOrder();
                        orders[1] = "-1";
                    }

                else if(ind == 1){ //if there are two costumers at the table
                    for(ctr = 0; ctr < costNum - 1; ctr++)                 //check which costumer is seated at given table
                        if(costumers[ctr].imAtThisTable() == tableNum)
                        costInd = ctr;

                    for(ctr2 = ctr; ctr2 < costNum - 1; ctr2++)
                        if(costumers[ctr2].imAtThisTable() == tableNum){
                        costInd2 = ctr2;
                        }
                    
                    orders[0] = costumers[ctr].createOrder();
                    orders[1] = costumers[ctr2].createOrder();
                    }
        }
            return orders;
      }

    public void enqueue(int order){}
    //implemented as EnlistOrderToCounter

    public void dequeue(){}
    //implemented as GetFoodFromCounter

    //all methods after this statements are executed upon button click
    public void getOrderFromTable(){
           Object tableNumb = getOrderTableNum.getSelectedItem();
               if(tableNumb == "-"){
               //print error message
               }
               else{
                   if(tableNumb == "1"){   //go to table to get order
                   server.setXY(380, 200);
                   }
                   else if(tableNumb == "2"){   //go to table to get order
                   server.setXY(550, 200);
                   }
                   else if(tableNumb == "3"){   //go to table to get order
                   server.setXY(750, 200);
                   }
                   else if(tableNumb == "4"){   //go to table to get order
                   server.setXY(380, 500);
                   }
                   else if(tableNumb == "5"){   //go to table to get order
                   server.setXY(550, 500);
                   }
               costumerOrdersAtHand = getOrderFromCostumers(tableNumb);
               errorText.setText("Hand Orders: " + costumerOrdersAtHand[0] + ", " + costumerOrdersAtHand[1]);
               }
        }

    public void BringFoodToTable(){
            Object tableNumb = bringToTable.getSelectedItem();
            Object bringToTableHand = bringHandSelect.getSelectedItem();
            Object bringToAorB = bringAorB.getSelectedItem();

               if(tableNumb == "-"){
               //print error message
               }
               else if(tableNumb == "1"){   //go to table to serve order
               server.setXY(380, 200);
               }
               else if(tableNumb == "2"){   //go to table to serve order
               server.setXY(550, 200);
               }
               else if(tableNumb == "3"){   //go to table to serve order
               server.setXY(750, 200);
               }
               else if(tableNumb == "4"){   //go to table to serve order
               server.setXY(380, 500);
               }
               else if(tableNumb == "5"){   //go to table to serve order
               server.setXY(550, 500);
               }

            //check if costumer exists at selected Hand
            //check if costumer ordered the item at Hand

        }

    public void GetFoodFromCounter(){
        Object temp1, temp2;
            server.setXY(780, 170);
                   //check if food is at counter
                   //check if hands are full
                   //store foods at 2hands if available
            if(counterOrderQueue.size() == 0)
                errorText.setText("no orders yet!");
            else if(counterOrderQueue.size() == 1){
                    temp1 = counterOrderQueue.remove();
                    //errorText.setText("hello" + temp1);
                    if(temp1 == "1")
                         foodLeftHand = 1;
                     else
                         foodLeftHand = 2;
                         foodRightHand = -1;
                    }
            else{
                    if(counterOrderQueue.remove() == "1")
                         foodLeftHand = 1;
                    else
                         foodLeftHand = 2;
                     
                    if(counterOrderQueue.remove() == "1")
                         foodRightHand = 1;
                    else
                         foodRightHand = 2;
                }

            handContains.setText("LH: " + foodLeftHand + ", RH: " + foodRightHand);
            errorText.setText("Hand Orders: " + costumerOrdersAtHand[0] + ", " + costumerOrdersAtHand[1]);
            queueStatus.setText("On Queue: " + counterOrderQueue);
             
        }

    public void EnlistOrderToCounter(){ //this method adds orders taken from given table to the counter order queue
             //check if order exits
             server.setXY(450, 120);
             //costumerOrderQueue
             if(costumerOrdersAtHand[0] == "-1" && costumerOrdersAtHand[1] == "-1") //print message if no orders are at hand
                 errorText.setText("no orders to be enlisted!");

             else if(costumerOrdersAtHand[1] == "-1")
                 counterOrderQueue.addFirst(costumerOrdersAtHand[0]);   //if only one order is at hand, enqueue

             else{
                 counterOrderQueue.addFirst(costumerOrdersAtHand[0]);   //if two orders were given from table
                 counterOrderQueue.addFirst(costumerOrdersAtHand[0]);
             }
             costumerOrdersAtHand[0] = "-1";  //delete orders from hand
             costumerOrdersAtHand[1] = "-1";  //delete orders from hand
             queueStatus.setText("On Queue: " + counterOrderQueue);
             
        }

    public void CollectPayment(){
            Object tableNumb = collectTable.getSelectedItem();

               if(tableNumb == "-"){
               //print error message
               }
               else if(tableNumb == "1"){   //go to table to collect payment
               server.setXY(380, 200);
               }
               else if(tableNumb == "2"){   //go to table to collect payment
               server.setXY(550, 200);
               }
               else if(tableNumb == "3"){   //go to table to collect payment
               server.setXY(750, 200);
               }
               else if(tableNumb == "4"){   //go to table to collect payment
               server.setXY(380, 500);
               }
               else if(tableNumb == "5"){   //go to table to collect payment
               server.setXY(550, 500);
               }
            //check if costumer exists at selected table
        }

    public void GoCleanTable(){
             Object tableNumb = cleanTableNum.getSelectedItem();
               if(tableNumb == "-"){
               //print error message
               }
               else if(tableNumb == "1"){   //go to table to get order
               server.setXY(380, 200);
               }
               else if(tableNumb == "2"){   //go to table to get order
               server.setXY(550, 200);
               }
               else if(tableNumb == "3"){   //go to table to get order
               server.setXY(750, 200);
               }
               else if(tableNumb == "4"){   //go to table to get order
               server.setXY(380, 500);
               }
               else if(tableNumb == "5"){   //go to table to get order
               server.setXY(550, 500);
               }
             //check is dirty plates exist
             //store to hands
        }

    public void GoToDishWashBin(){
            server.setXY(320, 170);
        }

    public void GetCleanPlates(){
            server.setXY(320, 170);
            //check if dirty plates exist
            //store
        }

    public void BringPlatesToCounter(){
            server.setXY(570, 170);
            //store plates to counter
        }

    public void MoveCostumersToLine(){
            //CostumersOnMap++;

        }

    public void sitCostumer(Object costumerNum){
            //remove costumer from line
            Object tableNum = costToTableNum.getSelectedItem();
            Object seat = costToSeat.getSelectedItem();
            if(tableNum == "1"){
                tables[0].sitCostumer(seat);
                costumers[0].changePos(tableNum, seat);
            }

            else if(tableNum == "2"){
                tables[1].sitCostumer(seat);
                costumers[0].changePos(tableNum, seat);
            }

            else if(tableNum == "3"){
                tables[2].sitCostumer(seat);
                costumers[0].changePos(tableNum, seat);
            }

            else if(tableNum == "4"){
                tables[3].sitCostumer(seat);
                costumers[0].changePos(tableNum, seat);
            }

            else if(tableNum == "5"){
                tables[4].sitCostumer(seat);
                costumers[0].changePos(tableNum, seat);
            }
        }

     public class ButtonHandler implements ActionListener{
        public void actionPerformed(ActionEvent event) {
               if(event.getSource() == getGet)
                   getOrderFromTable();

               else if(event.getSource() == getOrderEnlist)     //when "Enlist Order" button is pressed
                   EnlistOrderToCounter();
               
               else if(event.getSource() == getFood)            //when Get Food button is pressed
                   GetFoodFromCounter();
               
               else if(event.getSource() == bringServe)         //when Serve Food button is pressed
                   BringFoodToTable();

               else if(event.getSource() == collectGo)          //when Collect Payment button is pressed
                   CollectPayment();

               else if(event.getSource() == cleanGo)
                   GoCleanTable();

               else if(event.getSource() == cleanToWash)
                   GoToDishWashBin();

               else if(event.getSource() == cleanPlatesGoGet)
                   GetCleanPlates();

               else if(event.getSource() == cleanPlatesToCounter)
                   BringPlatesToCounter();

               else if(event.getSource() == moreCost)
                   MoveCostumersToLine();

               else if(event.getSource() == sitCost)
                   sitCostumer(costLineNum.getSelectedItem());

               }
    }

        public static void main (String[] args) {
        JFrame frame = new JFrame ("San Diego, Lau, Ngo - Just Got Queued");
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        //frame.setBackGround(Color.White);
        frame.getContentPane().add (new Main());
        frame.pack();
        frame.setResizable(false);
        frame.setVisible (true);
    }
}

*/
package queueddas;

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class Main extends JPanel implements MouseListener, MouseMotionListener{
    private JButton bringServe;
    private JComboBox costLineNum;
    private JComboBox costToTableNum;
    private JComboBox costToSeat;
    private JButton moreCost;
    private JButton sitCost;
    private JLabel costumerQueue;
    private JComboBox getOrderTableNum;
    private JButton getGet;
    private JLabel getOrderLabel;
    private JButton getOrderEnlist;
    private JLabel serveOrderLabel;
    private JButton getFood;
    private JLabel bringFoodLabel;
    private JComboBox bringHandSelect;
    private JComboBox bringToTable;
    private JComboBox bringAorB;
    private JLabel collectPayment;
    private JComboBox collectTable;
    private JButton collectGo;
    private JLabel cleanTable;
    private JButton cleanGo;
    private JComboBox cleanTableNum;
    private JButton cleanToWash;
    private JLabel cleanBringTo;
    private JButton cleanPlatesGoGet;
    private JButton cleanPlatesToCounter;
    private JLabel errorText;
    private JLabel errorNoti;
    public JLabel queueStatus;
    public JLabel handContains;
    public JLabel mouseCoords;
    public int CostumersCreated = 0;
    public Object costumerOrdersAtHand[];
    public int foodRightHand;
    public int foodLeftHand;
    public final int costNum = 1;
    private ImageStore background;
    private ImageStore podium;
    private Server server;
    private Timer timer;
    private Costumer[] costumers;
    private Table[] tables;
    private LinkedList counterOrderQueue;


    public Main() {//all statements in this constructor are for initialization purposes

        //construct preComponents
        String[] costLineNumItems = {"-", "1", "2", "3", "4"};
        String[] costToTableNumItems = {"-", "1", "2", "3", "4", "5"};
        String[] costToSeatItems = {"-", "A", "B"};
        String[] bringHandSelectItems = {"-", "Left Hand", "Right Hand"};
        String[] bringToTableItems = {"-", "1", "2", "3", "4", "5"};
        String[] bringAorBItems = {"-", "A", "B"};
        String[] getOrderAorBItems = {"-", "A", "B"};
        String[] getOrderTableNumItems = {"-", "1", "2", "3", "4", "5"};
        String[] collectTableItems = {"-", "1", "2", "3", "4", "5"};
        String[] cleanTableNumItems = {"-", "1", "2", "3", "4", "5"};

        //construct components
        getOrderTableNum = new JComboBox (getOrderTableNumItems);
        getOrderLabel = new JLabel ("Get Order");
        getOrderEnlist = new JButton ("Enlist Order");
        getGet = new JButton("Get!");
        serveOrderLabel = new JLabel ("Serve Order");
        bringFoodLabel = new JLabel ("Bring Food to:");
        bringHandSelect = new JComboBox (bringHandSelectItems);
        bringToTable = new JComboBox (bringToTableItems);
        bringAorB = new JComboBox (bringAorBItems);
        bringServe = new JButton ("Serve Food");
        costumerQueue = new JLabel ("Costumer:");
        getFood = new JButton ("Get Food");
        collectPayment = new JLabel ("Collect Payment");
        collectTable = new JComboBox (collectTableItems);
        collectGo = new JButton ("Go!");
        cleanTable = new JLabel ("Clean Table");
        cleanGo = new JButton ("Go!");
        cleanTableNum = new JComboBox (cleanTableNumItems);
        cleanToWash = new JButton ("ToDishwash");
        cleanBringTo = new JLabel ("Get Clean Plates");
        cleanPlatesGoGet = new JButton ("Go!");
        cleanPlatesToCounter = new JButton("To Counter");
        errorText = new JLabel ("Errors Here");
        errorNoti = new JLabel ("Error Notifications");
        costLineNum = new JComboBox (costLineNumItems);
        costToTableNum = new JComboBox (costToTableNumItems);
        costToSeat = new JComboBox (costToSeatItems);
        sitCost = new JButton ("Sit");
        moreCost = new JButton("More Costumers!");
        queueStatus = new JLabel("empty queue");
        handContains = new JLabel("LH: RH:");
        mouseCoords = new JLabel("MouseXY:");

        //adjust size and set layout
        setPreferredSize (new Dimension (1020, 670));
        setLayout (null);

        //add components
        add (bringServe);
        add (costLineNum);
        add (costToTableNum);
        add (costToSeat);
        add (sitCost);
        add (moreCost);
        add (costumerQueue);
        add (getOrderTableNum);
        add (getOrderLabel);
        add (getOrderEnlist);
        add (serveOrderLabel);
        add (getFood);
        add (bringFoodLabel);
        add (bringHandSelect);
        add (bringToTable);
        add (bringAorB);
        add (collectPayment);
        add (collectTable);
        add (collectGo);
        add (cleanTable);
        add (cleanGo);
        add (cleanTableNum);
        add (cleanToWash);
        add (cleanBringTo);
        add (cleanPlatesGoGet);
        add (cleanPlatesToCounter);
        add (errorText);
        add (errorNoti);
        add (getGet);
        add (queueStatus);
        add (handContains);
        add (mouseCoords);

        //set component bounds (only needed by Absolute Positioning)
        bringServe.setBounds (25, 230, 110, 25);
        costLineNum.setBounds (785, 625, 40, 20);
        costToTableNum.setBounds (840, 625, 35, 20);
        costToSeat.setBounds (880, 625, 35, 20);
        moreCost.setBounds (550, 625, 140, 20);
        sitCost.setBounds (920, 625, 60, 20);
        costumerQueue.setBounds (715, 625, 65, 20);
        getOrderTableNum.setBounds (25, 40, 35, 25);
        getGet.setBounds(70, 40, 65, 25);
        getOrderLabel.setBounds (15, 20, 60, 25);
        getOrderEnlist.setBounds (25, 70, 110, 25);
        serveOrderLabel.setBounds (15, 100, 75, 25);
        getFood.setBounds (25, 120, 110, 25);
        bringFoodLabel.setBounds (15, 150, 100, 25);
        bringHandSelect.setBounds (25, 200, 80, 25);
        bringToTable.setBounds (25, 170, 35, 25);
        bringAorB.setBounds (65, 170, 35, 25);
        collectPayment.setBounds (20, 260, 100, 25);
        collectTable.setBounds (30, 280, 35, 25);
        collectGo.setBounds (70, 280, 65, 25);
        cleanTable.setBounds (20, 310, 100, 25);
        cleanGo.setBounds (70, 330, 65, 25);
        cleanTableNum.setBounds (30, 330, 35, 25);
        cleanToWash.setBounds (30, 360, 105, 25);
        cleanBringTo.setBounds (20, 390, 115, 25);
        cleanPlatesGoGet.setBounds (30, 410, 105, 25);
        cleanPlatesToCounter.setBounds(30, 440, 105, 25);
        errorText.setBounds (30, 470, 105, 70);
        errorNoti.setBounds (20, 470, 110, 25);
        queueStatus.setBounds(30, 500, 110, 50);
        handContains.setBounds(30, 550, 110, 50);
        mouseCoords.setBounds(30, 550, 150, 150);

        //errorText.setForeground(WHITE);

        //images
        background = new ImageStore("bg.jpg");
        podium = new ImageStore("podium.png");
        server = new Server();
        counterOrderQueue = new LinkedList();
        costumerOrdersAtHand = new Object[2];
        costumers = new Costumer[12];
        tables = new Table[5];

        tables[0] = new Table();
        tables[1] = new Table();
        tables[2] = new Table();
        tables[3] = new Table();
        tables[4] = new Table();

        costumers[0] = new Costumer();

        foodLeftHand = -1;
        foodRightHand = -1;
        costumerOrdersAtHand[0] = "-1";
        costumerOrdersAtHand[1] = "-1";


        //handlers
        ButtonHandler buttHandler = new ButtonHandler();

        //listners

        addMouseListener(this);
        addMouseMotionListener(this);
        getOrderEnlist.addActionListener(buttHandler);
        getGet.addActionListener(buttHandler);
        getFood.addActionListener(buttHandler);
        bringServe.addActionListener(buttHandler);
        collectGo.addActionListener(buttHandler);
        cleanGo.addActionListener(buttHandler);
        cleanToWash.addActionListener(buttHandler);
        sitCost.addActionListener(buttHandler);
        cleanPlatesGoGet.addActionListener(buttHandler);
        cleanPlatesToCounter.addActionListener(buttHandler);
        moreCost.addActionListener(buttHandler);

        setDoubleBuffered(true);
        //while(true)
            repaint();
    }

     public void paint(Graphics g){
       super.paint(g);
       Graphics2D backg = (Graphics2D)g;
       Graphics2D podi = (Graphics2D)g;
       Graphics2D server = (Graphics2D)g;
       Graphics2D costumer1 = (Graphics2D)g;


       backg.drawImage(background.getImage(), 200, 20, this);
       podi.drawImage(podium.getImage(), 435, 65, this);
       server.drawImage(this.server.getImage(), this.server.getX(), this.server.getY(), this);
       costumer1.drawImage(costumers[0].getImage(), costumers[0].getX(), costumers[0].getY(), this);
       Toolkit.getDefaultToolkit().sync();
       g.dispose();

   }

    public Object[] getOrderFromCostumers(Object tableNumb){
        int tableNum = 0;
        int ind = -1;
        Object orders[];
        //int costNum = 1;
        int ctr, ctr2;
        int costInd, costInd2;
        orders = new Object[2];

        tableNum = tableNumToInt(tableNumb);

        if((ind = tables[tableNum].isTableFull()) == -1){
            errorText.setText("No Costumers Yet!"); //print error message: no costumers on table
            orders[0] = "-1";
            orders[1] = "-1";
        }

        else{   if(ind == 0){ //if there is only one costumer at the table
                    for(ctr = 0; ctr < costNum - 1; ctr++)                 //check which costumer is seated at given table
                        if(costumers[ctr].imAtThisTable() == tableNum)
                        costInd = ctr;
                        orders[0] = costumers[ctr].createOrder();
                        orders[1] = "-1";
                    }

                else if(ind == 1){ //if there are two costumers at the table
                    for(ctr = 0; ctr < costNum - 1; ctr++)                 //check which costumer is seated at given table
                        if(costumers[ctr].imAtThisTable() == tableNum)
                        costInd = ctr;

                    for(ctr2 = ctr; ctr2 < costNum - 1; ctr2++)
                        if(costumers[ctr2].imAtThisTable() == tableNum){
                        costInd2 = ctr2;
                        }

                    orders[0] = costumers[ctr].createOrder();
                    orders[1] = costumers[ctr2].createOrder();
                    }
        }
            return orders;
      }

    public int tableNumToInt(Object tableNumb){
        int tableNum = 0;

        if(tableNumb == "1")
               tableNum = 0;
               else if(tableNumb == "2")
               tableNum = 1;
               else if(tableNumb == "3")
               tableNum = 2;
               else if(tableNumb == "4")
               tableNum = 3;
               else if(tableNumb == "5")
               tableNum = 4;

        return tableNum;
    }

    public int bringHandSelectToInt(){
        int ret = -1;

        if(bringHandSelect.getSelectedItem() == "Left Hand")
            ret = 1;
        else
            ret = 2;

        return ret;
    }
    
    public void GiveFoodToCostumer(Object tableNumb){
        int ind = -1;
        int tableNum = tableNumToInt(tableNumb);
        int hand = bringHandSelectToInt();
        int ctr, ctr2;
        int costInd;
        Object ord;

        if(hand == 1){
            if(foodLeftHand == 1)
                ord = "1";
            else
                ord = "2";
        }
        else{
            if(foodRightHand == 1)
                ord = "1";
            else
                ord = "2";
        }

        
        if((ind = tables[tableNum].isTableFull()) == -1){
            errorText.setText("No Costumers Yet!"); //print error message: no costumers on table
            }
        else if(ind == 0 || ind == 1){
            for(ctr = 0; ctr < costNum - 1; ctr++){
            if(costumers[ctr].imAtThisTable() == tableNum){ //check if costumer is at the table
                costInd = ctr;
                if(costumers[ctr].myOrder(ord) == 1){ //check if the food on selected hand is same as costumer's order
                       if(hand == 1){
                           foodLeftHand = -1;           
                       }
                       else{
                           foodRightHand = -1;
                           }
                       //display food
                }
                
            }}}
    }


    public void enqueue(int order){}
    //implemented as EnlistOrderToCounter

    public void dequeue(){}
    //implemented as GetFoodFromCounter

    //all methods after this statements are executed upon button click
    public void getOrderFromTable(Object tableNumb){
           //Object tableNumb = getOrderTableNum.getSelectedItem();
               if(tableNumb == "-"){
               //print error message
               }
               else{
                   if(tableNumb == "1"){   //go to table to get order
                   server.setXY(380, 200);
                   }
                   else if(tableNumb == "2"){   //go to table to get order
                   server.setXY(550, 200);
                   }
                   else if(tableNumb == "3"){   //go to table to get order
                   server.setXY(750, 200);
                   }
                   else if(tableNumb == "4"){   //go to table to get order
                   server.setXY(380, 500);
                   }
                   else if(tableNumb == "5"){   //go to table to get order
                   server.setXY(550, 500);
                   }
               costumerOrdersAtHand = getOrderFromCostumers(tableNumb);
               errorText.setText("Hand Orders: " + costumerOrdersAtHand[0] + ", " + costumerOrdersAtHand[1]);
               }
        }

    public void BringFoodToTable(){
            Object tableNumb = bringToTable.getSelectedItem();
            Object bringToTableHand = bringHandSelect.getSelectedItem();
            Object bringToAorB = bringAorB.getSelectedItem();

               if(tableNumb == "-"){
               //print error message
               }
               else if(tableNumb == "1"){   //go to table to serve order
               server.setXY(380, 200);
               }
               else if(tableNumb == "2"){   //go to table to serve order
               server.setXY(550, 200);
               }
               else if(tableNumb == "3"){   //go to table to serve order
               server.setXY(750, 200);
               }
               else if(tableNumb == "4"){   //go to table to serve order
               server.setXY(380, 500);
               }
               else if(tableNumb == "5"){   //go to table to serve order
               server.setXY(550, 500);
               }

            //check if costumer exists at selected Hand
            //check if costumer ordered the item at Hand

        }

    public void GetFoodFromCounter(){
        Object temp1, temp2;
            server.setXY(780, 170);
                   //check if food is at counter
                   //check if hands are full
                   //store foods at 2hands if available
            if(counterOrderQueue.size() == 0)
                errorText.setText("no orders yet!");
            else if(counterOrderQueue.size() == 1){
                    temp1 = counterOrderQueue.remove();
                    //errorText.setText("hello" + temp1);
                    if(temp1 == "1")
                         foodLeftHand = 1;
                     else
                         foodLeftHand = 2;
                         foodRightHand = -1;
                    }
            else{
                    if(counterOrderQueue.remove() == "1")
                         foodLeftHand = 1;
                    else
                         foodLeftHand = 2;

                    if(counterOrderQueue.remove() == "1")
                         foodRightHand = 1;
                    else
                         foodRightHand = 2;
                }

            handContains.setText("LH: " + foodLeftHand + ", RH: " + foodRightHand);
            errorText.setText("Hand Orders: " + costumerOrdersAtHand[0] + ", " + costumerOrdersAtHand[1]);
            queueStatus.setText("On Queue: " + counterOrderQueue);

        }

    public void EnlistOrderToCounter(){ //this method adds orders taken from given table to the counter order queue
             //check if order exits
             server.setXY(450, 120);
             //costumerOrderQueue
             if(costumerOrdersAtHand[0] == "-1" && costumerOrdersAtHand[1] == "-1") //print message if no orders are at hand
                 errorText.setText("no orders to be enlisted!");

             else if(costumerOrdersAtHand[1] == "-1")
                 counterOrderQueue.addFirst(costumerOrdersAtHand[0]);   //if only one order is at hand, enqueue

             else{
                 counterOrderQueue.addFirst(costumerOrdersAtHand[0]);   //if two orders were given from table
                 counterOrderQueue.addFirst(costumerOrdersAtHand[0]);
             }
             costumerOrdersAtHand[0] = "-1";  //delete orders from hand
             costumerOrdersAtHand[1] = "-1";  //delete orders from hand
             queueStatus.setText("On Queue: " + counterOrderQueue);

        }

    public void CollectPayment(){
            Object tableNumb = collectTable.getSelectedItem();

               if(tableNumb == "-"){
               //print error message
               }
               else if(tableNumb == "1"){   //go to table to collect payment
               server.setXY(380, 200);
               }
               else if(tableNumb == "2"){   //go to table to collect payment
               server.setXY(550, 200);
               }
               else if(tableNumb == "3"){   //go to table to collect payment
               server.setXY(750, 200);
               }
               else if(tableNumb == "4"){   //go to table to collect payment
               server.setXY(380, 500);
               }
               else if(tableNumb == "5"){   //go to table to collect payment
               server.setXY(550, 500);
               }
            //check if costumer exists at selected table
        }

    public void GoCleanTable(){
             Object tableNumb = cleanTableNum.getSelectedItem();
               if(tableNumb == "-"){
               //print error message
               }
               else if(tableNumb == "1"){   //go to table to get order
               server.setXY(380, 200);
               }
               else if(tableNumb == "2"){   //go to table to get order
               server.setXY(550, 200);
               }
               else if(tableNumb == "3"){   //go to table to get order
               server.setXY(750, 200);
               }
               else if(tableNumb == "4"){   //go to table to get order
               server.setXY(380, 500);
               }
               else if(tableNumb == "5"){   //go to table to get order
               server.setXY(550, 500);
               }
             //check is dirty plates exist
             //store to hands
        }

    public void GoToDishWashBin(){
            server.setXY(320, 170);
        }

    public void GetCleanPlates(){
            server.setXY(320, 170);
            //check if dirty plates exist
            //store
        }

    public void BringPlatesToCounter(){
            server.setXY(570, 170);
            //store plates to counter
        }

    public void MoveCostumersToLine(){
            //CostumersOnMap++;

        }

    public void sitCostumer(Object costumerNum){
            //remove costumer from line
            Object tableNum = costToTableNum.getSelectedItem();
            Object seat = costToSeat.getSelectedItem();
            if(tableNum == "1"){
                tables[0].sitCostumer(seat);
                costumers[0].changePos(tableNum, seat);
            }

            else if(tableNum == "2"){
                tables[1].sitCostumer(seat);
                costumers[0].changePos(tableNum, seat);
            }

            else if(tableNum == "3"){
                tables[2].sitCostumer(seat);
                costumers[0].changePos(tableNum, seat);
            }

            else if(tableNum == "4"){
                tables[3].sitCostumer(seat);
                costumers[0].changePos(tableNum, seat);
            }

            else if(tableNum == "5"){
                tables[4].sitCostumer(seat);
                costumers[0].changePos(tableNum, seat);
            }
        }

    public void mouseClicked(MouseEvent e) {
        mouseCoords.setText(String.format("Clicked at [%d , %d] ",e.getX(), e.getY()));
        //throw new UnsupportedOperationException("Not supported yet.");
        if (e.getX() >= 374 && e.getX() <= 433 && e.getY() >= 307 && e.getY() <= 367) {
        getOrderFromTable("1");
        }
        else if (e.getX() >= 555 && e.getX() <= 618 && e.getY() >= 307 && e.getY() <= 367) {
        getOrderFromTable("2");
        }
        else if (e.getX() >= 745 && e.getX() <= 807 && e.getY() >= 307 && e.getY() <= 367) {
        getOrderFromTable("3");
        }
        else if (e.getX() >= 371 && e.getX() <= 433 && e.getY() >= 470 && e.getY() <= 528) {
        getOrderFromTable("4");
        }
        else if (e.getX() >= 555 && e.getX() <= 618 && e.getY() >= 470 && e.getY() <= 528) {
        getOrderFromTable("5");
        }

        //clicked at counter
        else if (e.getX() >= 445 && e.getX() <= 493 && e.getY() >= 67 && e.getY() <= 177) {
        EnlistOrderToCounter();
        }
        else if (e.getX() >= 527 && e.getX() <= 822 && e.getY() >= 141 && e.getY() <= 234) {
        GetFoodFromCounter();
        }
        //deliver food to costumers
        else if(e.getX() >= 305 && e.getX() <= 360 && e.getY() >= 274 && e.getY() <= 373) {
            server.setXY(380, 200); GiveFoodToCostumer("1");
            BringFoodToTable();
            //go to table 1, deliver to costumer A
        }
        else if(e.getX() >= 438 && e.getX() <= 488 && e.getY() >= 274 && e.getY() <= 373) {
            server.setXY(380, 200); GiveFoodToCostumer("1");
            //go to table 1, deliver to costumer B
        }
        else if(e.getX() >= 500 && e.getX() <= 550 && e.getY() >= 274 && e.getY() <= 373) {
            server.setXY(550, 200); GiveFoodToCostumer("2");
            //go to table 2, deliver to costumer A
        }
        else if(e.getX() >= 631 && e.getX() <= 677 && e.getY() >= 274 && e.getY() <= 373) {
            server.setXY(550, 200); GiveFoodToCostumer("2");
            //go to table 2, deliver to costumer B
        }
        else if(e.getX() >= 689 && e.getX() <= 740 && e.getY() >= 274 && e.getY() <= 373) {
            server.setXY(750, 200); GiveFoodToCostumer("3");
            //go to table 3, deliver to costumer A
        }
        else if(e.getX() >= 819 && e.getX() <= 865 && e.getY() >= 274 && e.getY() <= 373) {
            server.setXY(750, 200); GiveFoodToCostumer("3");
            //go to table 3, deliver to costumer B
        }
        else if(e.getX() >= 309 && e.getX() <= 360 && e.getY() >= 435 && e.getY() <= 530) {
            server.setXY(380, 500); GiveFoodToCostumer("4");
            //go to table 4, deliver to costumer A
        }
        else if(e.getX() >= 440 && e.getX() <= 485 && e.getY() >= 435 && e.getY() <= 530) {
            server.setXY(380, 500); GiveFoodToCostumer("4");
            //go to table 4, deliver to costumer B
        }
        else if(e.getX() >= 500 && e.getX() <= 550 && e.getY() >= 435 && e.getY() <= 530) {
            server.setXY(550, 500); GiveFoodToCostumer("5");
            //go to table 5, deliver to costumer A
        }
        else if(e.getX() >= 628 && e.getX() <= 670 && e.getY() >= 435 && e.getY() <= 530) {
            server.setXY(550, 500); GiveFoodToCostumer("5");
            //go to table 5, deliver to costumer B
        }
            handContains.setText("LH: " + foodLeftHand + ", RH: " + foodRightHand);
            errorText.setText("Hand Orders: " + costumerOrdersAtHand[0] + ", " + costumerOrdersAtHand[1]);
            queueStatus.setText("On Queue: " + counterOrderQueue);

    }

    public void mousePressed(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseReleased(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseEntered(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseExited(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseDragged(MouseEvent e) {
       // throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseMoved(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

     public class ButtonHandler implements ActionListener{
        public void actionPerformed(ActionEvent event) {
               if(event.getSource() == getGet)
                   getOrderFromTable("0");

               else if(event.getSource() == getOrderEnlist)     //when "Enlist Order" button is pressed
                   EnlistOrderToCounter();

               else if(event.getSource() == getFood)            //when Get Food button is pressed
                   GetFoodFromCounter();

               else if(event.getSource() == bringServe)         //when Serve Food button is pressed
                   BringFoodToTable();

               else if(event.getSource() == collectGo)          //when Collect Payment button is pressed
                   CollectPayment();

               else if(event.getSource() == cleanGo)
                   GoCleanTable();

               else if(event.getSource() == cleanToWash)
                   GoToDishWashBin();

               else if(event.getSource() == cleanPlatesGoGet)
                   GetCleanPlates();

               else if(event.getSource() == cleanPlatesToCounter)
                   BringPlatesToCounter();

               else if(event.getSource() == moreCost)
                   MoveCostumersToLine();

               else if(event.getSource() == sitCost)
                   sitCostumer(costLineNum.getSelectedItem());

               }
    }

        public static void main (String[] args) {
        JFrame frame = new JFrame ("San Diego, Lau, Ngo - Just Got Queued");
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        //frame.setBackGround(Color.White);
        frame.getContentPane().add (new Main());
        frame.pack();
        frame.setResizable(false);
        frame.setVisible (true);
    }
}